package com.production.CoursePlatform.controller;

import com.production.CoursePlatform.response.ApiResponse;
import com.production.CoursePlatform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    //此接口已检验
    @Autowired
    private UserService userService;

    // http://localhost:8080/user/login?IDnumber=22301161&password=123456
    @RequestMapping(value = "/user/login", method = RequestMethod.POST)
    public ResponseEntity<String> login(@RequestParam String IDnumber, @RequestParam String password) {
        int i = userService.login(IDnumber,password);
        if (i!=3){
            return ResponseEntity.ok("身份信息：" + i);
        }else
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


    // http://localhost:8080/user/login?IDnumber&oldPassword&newPassword
    @RequestMapping(value = "/user/change", method = RequestMethod.POST)
    public ApiResponse changePassword(@RequestParam String IDnumber, @RequestParam String oldPassword, @RequestParam String newPassword) {
        return userService.changePassword(IDnumber, oldPassword, newPassword);
    }

}
